/*
 * @Author: Lauxb
 * @Date: 2021-03-26 15:58:36
 * @LastEditTime: 2021-07-26 09:39:23
 * @LastEditors: G.TAO
 * @Description: 测量
 */

import {
  registerMouseHandler,
  registerLongMouseHandler,
  resetMouseHandler,
  resetLongMouseHandler,
  MOUSE_TYPE
} from "@tys/chaos/mouse";

export {
  registerMouseHandler,
  registerLongMouseHandler,
  resetMouseHandler,
  resetLongMouseHandler,
  MOUSE_TYPE
};

/**
 * 测量模式
 */
export const MEASURE_MODE = {
  DISTANCE: 0,
  AREA: 1,
  DVH: 2,
  DVHX: 3
};
/**
 * 测量类型:: Ground: 1 Raster: 3 S3mModel: 2  Space: 0
 */
export const MEASURE_TYPE = {
  Space: 0, //空间模式
  Ground: 1, //贴地模式
  S3mModel: 2, //贴对象模式
  Raster: 3 //栅格模式
};

/**
 * 创建距离测量事件处理器
 * @param {Object} chaos
 * @param {Enum} measureMode
 * @param {Enum} measureType
 * @returns MeasureHandler
 */
export const createMeasureHandler = (chaos, measureMode, measureType) => {
  const handler = new chaos.cesium.MeasureHandler(
    chaos.viewer,
    measureMode,
    measureType
  );
  return handler;
};

/**
 * 设置测量绘制风格
 * @param {Object} chaos 三维场景管理器
 * @param {MeasureHandler} measureHandler MeasureHandler
 */
export const setMeasureStyle = (chaos, measureHandler) => {
  measureHandler.activeEvt.addEventListener(isActive => {
    if (isActive) {
      chaos.viewer.enableCursorStyle = false;
      chaos.viewer._element.style.cursor = "crosshair";

      measureHandler.lineColor =
        chaos.cesium.Color.fromCssColorString("#cc00ff");
      measureHandler.lineWidth = 2;
    } else {
      chaos.viewer.enableCursorStyle = true;
      chaos.viewer._element.style.cursor = "";
    }
  });
};

/**
 * 设置测量文字样式
 * @param {Object} chaos 三维场景管理器
 * @param {Object} labelEntity 文字实体
 * @param {String} type 标签类型 "V","H","DIS","AREA"
 */
export const setMeasureTextStyle = (chaos, labelEntity, type) => {
  if (labelEntity) {
    labelEntity.fillColor = chaos.cesium.Color.WHITE;
    labelEntity.backgroundColor =
      chaos.cesium.Color.fromCssColorString("rgba(0,0,0,1)").withAlpha(0.5);
    labelEntity.outlineColor =
      chaos.cesium.Color.fromCssColorString("rgba(0,0,0,1)");
    labelEntity.outlineWidth = 1;
    labelEntity.scale = 1;
    labelEntity.font = "500 16px sans-serif";

    switch (type) {
      case "AREA":
      case "V":
        labelEntity.pixelOffset = new chaos.cesium.Cartesian2(1.0, 0.0);
        labelEntity.verticalOrigin = chaos.cesium.VerticalOrigin.CENTER;
        break;
      case "H":
        labelEntity.pixelOffset = new chaos.cesium.Cartesian2(0.0, 0.0);
        labelEntity.verticalOrigin = chaos.cesium.VerticalOrigin.BOTTOM;
        break;
      case "DIS":
        labelEntity.pixelOffset = new chaos.cesium.Cartesian2(10.0, 0.0);
        labelEntity.verticalOrigin = chaos.cesium.VerticalOrigin.BOTTOM;
        break;
    }
  }
};
